package com.youbug.mall.ware_wms.controller;


import com.youbug.common.constant.WareConstant;
import com.youbug.common.vo.CommonSelectLongValVo;
import com.youbug.common.vo.CommonSelectVo;
import com.youbug.common.vo.QueryVo;
import com.youbug.mall.ware_wms.entity.WmsPurchase;
import com.youbug.mall.ware_wms.service.IWmsPurchaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.mall.ware_wms.vo.DistributeVo;
import com.youbug.mall.ware_wms.vo.MergeVo;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 采购信息 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2024-05-05
 */
@RestController
@RequestMapping("/wmsPurchase")
public class WmsPurchaseController {
@Autowired
private IWmsPurchaseService wmsPurchaseService;

    @PostMapping("/getWmsPurchasePage")
    public R<IPage<WmsPurchase>> getWmsPurchasePage(@RequestBody QueryVo<WmsPurchase> queryVo){

        IPage<WmsPurchase> wmsPurchases = wmsPurchaseService.getWmsPurchasePage(queryVo);

        return R.ok(wmsPurchases);
    }

    @GetMapping("/getUnreceicedWmsPurchasePage/{wareId}")
    public R<IPage<WmsPurchase>> getUnreceicedWmsPurchasePage(@PathVariable Long wareId){

        IPage<WmsPurchase> wmsPurchases = wmsPurchaseService.getUnreceicedWmsPurchasePage(wareId);

        return R.ok(wmsPurchases);
    }

    @GetMapping("/getWmsPurchaseById/{id}")
    public R<WmsPurchase> getWmsPurchaseById(@PathVariable Integer id){

        WmsPurchase wmsPurchase = wmsPurchaseService.getById(id);

        return R.ok(wmsPurchase);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody WmsPurchase wmsPurchase){
        wmsPurchase.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
        boolean save = wmsPurchaseService.save(wmsPurchase);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody WmsPurchase wmsPurchase){

        boolean update = wmsPurchaseService.updateById(wmsPurchase);

        return  R.ok(update);
    }

    @PostMapping("/distribute")
    public R<Boolean> distribute(@RequestBody DistributeVo vo){

        boolean distribute = wmsPurchaseService.distribute(vo);

        return  R.ok(distribute);
    }
    @PostMapping("/merge")
    public R<Boolean> merge(@RequestBody MergeVo vo){

        boolean merge = wmsPurchaseService.mergePurchase(vo);

        return  R.ok(merge);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Long id){

        boolean remove = wmsPurchaseService.removeById(id);

        return  R.ok(remove);
    }

    @GetMapping("/checkHasDetail/{id}")
    public R<Boolean> checkHasDetail(@PathVariable Long id){

        boolean hasDetail = wmsPurchaseService.checkHasDetail(id);

        return  R.ok(hasDetail);
    }

    @GetMapping("/getAllWareSelect")
    public R<List<CommonSelectLongValVo>> getAllWareSelect(){

        List<CommonSelectLongValVo> vos = wmsPurchaseService.getAllWareSelect();

        return  R.ok(vos);
    }
}

